package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.HeartbeatMsg;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.IHeartbeatMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 终端心跳上传报文记录Controller
 *
 * @author zjw
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/system/heartbeatMsg")
public class HeartbeatMsgController extends BaseController {
    @Autowired
    private IHeartbeatMsgService heartbeatMsgService;

    /**
     * 查询终端心跳上传报文记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:msg:list')")
    @GetMapping("/list")
    public TableDataInfo list(HeartbeatMsg heartbeatMsg) {
        startPage();
        List<HeartbeatMsg> list = heartbeatMsgService.selectHeartbeatMsgList(heartbeatMsg);
        return getDataTable(list);
    }

    /**
     * 导出终端心跳上传报文记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:msg:export')")
    @Log(title = "终端心跳上传报文记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HeartbeatMsg heartbeatMsg) {
        List<HeartbeatMsg> list = heartbeatMsgService.selectHeartbeatMsgList(heartbeatMsg);
        ExcelUtil<HeartbeatMsg> util = new ExcelUtil<HeartbeatMsg>(HeartbeatMsg.class);
        util.exportExcel(response, list, "终端心跳上传报文记录数据");
    }

    /**
     * 获取终端心跳上传报文记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:msg:query')")
    @GetMapping(value = "/{msgid}")
    public AjaxResult getInfo(@PathVariable("msgid") Long msgid) {
        return success(heartbeatMsgService.selectHeartbeatMsgByMsgid(msgid));
    }

    /**
     * 新增终端心跳上传报文记录
     */
    @PreAuthorize("@ss.hasPermi('system:msg:add')")
    @Log(title = "终端心跳上传报文记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HeartbeatMsg heartbeatMsg) {
        return toAjax(heartbeatMsgService.insertHeartbeatMsg(heartbeatMsg));
    }

    /**
     * 修改终端心跳上传报文记录
     */
    @PreAuthorize("@ss.hasPermi('system:msg:edit')")
    @Log(title = "终端心跳上传报文记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HeartbeatMsg heartbeatMsg) {
        return toAjax(heartbeatMsgService.updateHeartbeatMsg(heartbeatMsg));
    }

    /**
     * 删除终端心跳上传报文记录
     */
    @PreAuthorize("@ss.hasPermi('system:msg:remove')")
    @Log(title = "终端心跳上传报文记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{msgids}")
    public AjaxResult remove(@PathVariable Long[] msgids) {
        return toAjax(heartbeatMsgService.deleteHeartbeatMsgByMsgids(msgids));
    }
}
